home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2.sit
/
Raven 1.2
/
Source
/
Foundation
/
Common
/
ZSimpleAllocator.h
< prev
next >
Wrap
Text File
|
1997-06-17
|
3KB
|
99 lines
/*
* File: ZSimpleAllocator.h
* Summary: Fast general purpose allocator.
* Written by: Jesse Jones
*
* Abstract: This uses the same algorithm MetroWerk's NEWMODE_FAST version of
* operator new. This is a fast and relatively simple algorithm but it
* does not return pools to the system. Note that TBestFitHeap is about
* as fast and does a much better job returning memory to the OS.
*
* Copyright ゥ 1997 Jesse Jones.
* For conditions of distribution and use, see copyright notice in ZTypes.h
*
* Change History (most recent first):
*
* <-> 1/28/97 JDJ Created
*/
#pragma once
#include <ZAllocator.h>
//-----------------------------------
// Forward References
//
struct SBlock;
struct SPool;
// ===================================================================================
// class TSimpleAllocator
// ===================================================================================
class TSimpleAllocator : public TAllocator {
typedef TAllocator Inherited;
//-----------------------------------
// Initialization/Destruction
//
public:
virtual ~TSimpleAllocator();
TSimpleAllocator(ulong initialSize, ulong poolSize, ulong hugeSize = 0);
// Heap will start with initialSize bytes. When the heap is
// exhausted a new pool with poolSize bytes will be allocated.
// Blocks larger than hugeSize are always allocated using NewPtr
// and never reused (0 means poolSize/4).
//-----------------------------------
// Inherited API
//
public:
virtual void* Allocate(ulong bytes);
virtual void Deallocate(void* block);
virtual ulong GetHeapSize() const {return mHeapSize;}
virtual ulong GetPoolCount() const {return mPoolCount;}
virtual ulong GetBlockSize(const void* ptr) const;
virtual ulong GetTotalBlockSize(const void* ptr) const;
#if DEBUG
virtual void ValidateBlock(const void* ptr) const;
virtual void ValidateHeap(BlockValidateHook hook = nil, void* refCon = nil) const;
#endif
//-----------------------------------
// Internal API
//
protected:
SBlock* AllocateFromPool(SPool* pool, ulong bytes);
SBlock* AllocateFromBlock(SBlock* candidate, const SBlock* end, ulong bytes);
SBlock* AllocateFromHeap(ulong bytes);
SPool* AllocatePool(ulong size);
//-----------------------------------
// Member Data
//
protected:
SPool* mFirstPool;
ulong mNewPoolSize;
ulong mHugeSize;
ulong mHeapSize;
ulong mPoolCount;
SBlock* mLastSplitBlock;
const SBlock* mLastEnd;
};